<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增行政组')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-group-add">
			<input id="leaderTableId" name="leaderId" type="hidden" />
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">行政组名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="groupName" id="groupName" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">行政组编码：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="groupCode" id="groupCode" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">组长：</label>
				<div class="col-sm-8">
					<div class="input-group">
						<input class="form-control" type="text" onclick="selectLeaderWindow()" id="leaderTableName" readonly="true">
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">显示顺序：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="groupSort" id="groupSort" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">行政组状态：</label>
				<div class="col-sm-8">
				    <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
						<input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<textarea id="remark" name="remark" class="form-control"></textarea>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "system/group";
        var treeId = $("#leaderId").val();
        var leaderId = treeId > 0 ? treeId : 1;
	    
		$("#form-group-add").validate({
			onkeyup: false,
			rules:{
                groupName:{
                    maxlength:50,
					remote: {
		                url: ctx + "system/group/checkGroupNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"groupName" : function() {
		                        return $.common.trim($("#groupName").val());
		                    }
		                }
		            }
				},
                groupCode:{
                    maxlength:60,
					remote: {
		                url: ctx + "system/group/checkGroupCodeUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"groupCode" : function() {
		                        return $.common.trim($("#groupCode").val());
		                    }
		                }
		            }
				},
				groupSort:{
                    maxlength:5,
					digits:true
				},
			},
			messages: {
		        "groupCode": {
		            remote: "行政组编码已经存在"
		        },
		        "groupName": {
		            remote: "行政组名称已经存在"
		        }
		    },
		    focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/add", $('#form-group-add').serialize());
	        }
	    }

        /*行政组管理-新增-选择组长列表*/
        function selectLeaderWindow() {
            var options = {
                title: '组长选择',
                width: "800",
                url: ctx + "system/user/selectUserList/"+leaderId,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#leaderTableId").val(body.find('#tableId').val());
            $("#leaderTableName").val(body.find('#tableName').val());
            $.modal.close(index);
        }
	</script>
</body>
</html>
